/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including but not limited to the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to provide persons with access to the Software
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGE OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

<template>
  <div class="container-header">
    <div
      class="header-background"
      :style="{
        backgroundImage: `url(${require('@/assets/playList/header_background.png')})`,
        paddingTop: `${topAvoidArea ? topAvoidArea : 8}px`,
      }"
    >
      <button class="back-button" @click="goBack">
        <img
          :src="require('../../../assets/playList/small_back.png')"
          alt="Back"
          class="back-icon"
        />
      </button>

      <div
        class="playlist-info"
        :style="{
          marginLeft: paddingHorizontal + 'px',
          marginRight: paddingHorizontal + 'px',
          width: 'auto',
        }"
      >
        <div class="image-wrapper">
          <img
            :src="require('../../../assets/playList/cover.png')"
            alt="Playlist Cover"
            class="playlist-image"
          />
          <div class="image-overlay">
            <span class="image-number">{{ imageNumber }}</span>
          </div>
        </div>
        <div class="playlist-text">
          <h2 class="text-title">{{ playlistTitle }}</h2>
          <p class="text-description" :title="playlistDescription">
            {{ playlistDescription }}
          </p>
          <p class="author">{{ 'Christopher' }}</p>
        </div>
      </div>

      <div
        class="images-row"
        :style="{
          marginLeft: paddingHorizontal + 'px',
          marginRight: paddingHorizontal + 'px',
          width: 'auto',
        }"
      >
        <img
          v-for="(image, index) in fourImages"
          :key="index"
          :src="image"
          :alt="'Action ' + (index + 1)"
          class="action-image"
        />
      </div>
    </div>

    <div
      class="list-header"
      :style="{
        marginLeft: listHeaderImage + 'px',
        marginRight: listHeaderImage + 'px',
        width: 'auto',
      }"
    >
      <img
        :src="require('../../../assets/playList/play_icon.png')"
        alt="Play All"
        class="list-header-icon"
      />
      <span class="list-header-text">播放全部</span>
      <span class="list-header-text">{{ songsLength }}</span>
      <div class="flex-style"></div>
      <img
        :src="require('../../../assets/playList/show_all.png')"
        alt="Show All"
        class="open-icon"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, onBeforeUnmount, defineProps } from 'vue';
import { useRouter } from 'vue-router';
import { BreakpointManager } from '@hadss/web_adaptive_layout_ui';

const props = defineProps({
  songsLength: {
    type: [Number, String],
    required: true,
  },
  topAvoidArea: {
    type: Number,
    default: 0,
  },
});

const router = useRouter();
const imageNumber = ref('3456万');
const playlistTitle = ref('轻快旋律：这里是疲倦灵魂栖息地');
const playlistDescription = ref(
  '怀旧使我快乐，人们总是以为自己的生活很枯燥/乏味，那是因为他们没有回过头来聆听那些曾陪伴过我们青春的旋律'
);
const fourImages = ref([
  require('../../../assets/playList/love_count.png'),
  require('../../../assets/playList/download_count.png'),
  require('../../../assets/playList/commen_count.png'),
  require('../../../assets/playList/share.png'),
]);
const paddingHorizontal = ref(16);
const listHeaderImage = ref(16);

const breakpointManager = new BreakpointManager();
const unsubscribe = breakpointManager.subscribeToBreakpoint(() => {
  paddingHorizontal.value = breakpointManager.useBreakpointValue({
    sm: 16,
    md: 113,
  });
  listHeaderImage.value = breakpointManager.useBreakpointValue({
    sm: 16,
    md: 24,
  });
});

const goBack = (): void => {
  router.go(-1);
};

onBeforeUnmount((): void => {
  if (unsubscribe) {
    unsubscribe();
  }
});
</script>

<style scoped>
.container-header {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.header-background {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-size: cover;
  background-repeat: unset;
  background-position: bottom;
}

.back-button {
  margin-left: 16px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.back-icon {
  width: 100%;
  height: 100%;
}

.playlist-info {
  display: flex;
  flex-direction: row;
  margin-top: 8px;
  height: 120px;
}

.image-wrapper {
  position: relative;
  margin-right: 15px;
}

.playlist-image {
  width: 112px;
  height: 112px;
}

.image-overlay {
  position: absolute;
  bottom: 12px;
  left: 6px;
}

.image-number {
  color: rgba(255, 255, 255, 0.86);
  font-size: 12px;
}

.playlist-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.text-title {
  text-align: start;
  font-size: 24px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.86);
  margin: 0;
}

.text-description {
  margin-top: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0;
}

.author {
  margin-top: 7px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 0;
}

.images-row {
  display: flex;
  flex-direction: row;
  margin-top: 12px;
  justify-content: space-between;
  margin-bottom: 32px;
}

.action-image {
  width: 48px;
  height: 48px;
}

.list-header {
  height: 48px;
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
}

.list-header-icon {
  width: 32px;
  height: 32px;
}

.list-header-text {
  margin-left: 8px;
  font-size: 18px;
  color: rgba(0, 0, 0, 0.9);
  font-weight: 700;
  line-height: 24px;
  margin-right: 6px;
}

.open-icon {
  width: 20px;
  height: 20px;
}

.flex-style {
  flex: 1;
}
</style>
